/**
 * @file goods.js
 * @author swan
 */
const app = getApp()

Page({
    data: {
        host: getApp().getUrl(),
        goodsList: []
    },
    onLoad: function () {

    },
    getSearchTxt(e) {
        this.setData({
            goodsName: e.detail.value
        })
    },
    searchSubmit(e) {
        var goodsName = this.data.goodsName;
        this.goodsList(goodsName);
    },
    goodsList(goodsName) {
        swan.showToast({
            title: '正在加载...',
            icon: 'loading',
            duration: 1500
        });
        swan.request({
            url: getApp().getUrl('/v1/goods-list'),
            data: {
                'goods_name': goodsName
            },
            success: res => {
                let data = res.data.data;
                this.setData({
                    goodsList: data,
                })
            },
            fail: err => {
                swan.showToast({
                    title: '商品展示失败',
                    icon: 'none'
                });
            }
        });
    },
    onGoodsTap: function (event) {
        var goodsId = event.currentTarget.dataset.goodsId;
        console.log(goodsId)
        swan.navigateTo({
            url: "../../goods/goods-detail/goods-detail?id=" + goodsId
        })
    },
});
